package top.lishuoboy.hutool.core.lang;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import top.lishuoboy.dependency.base.json.FastjsonUtil;

import java.util.HashMap;
import java.util.List;

@Slf4j
public class TreeNodeTest {
    @Test
    public void test1() {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("zhangsan", "张三");
        hashMap.put("lisi", "李四");
        List<TreeNode<Integer>> list = ListUtil.list(false,
                new TreeNode<Integer>().setId(0).setExtra(hashMap),
                new TreeNode<Integer>().setId(1).setParentId(0).setExtra(hashMap),
                new TreeNode<Integer>().setId(2).setParentId(1).setWeight(2).setExtra(hashMap),
                new TreeNode<Integer>().setId(3).setParentId(1).setWeight(1),
                new TreeNode<Integer>().setId(4).setParentId(0)
        );
        Tree<Integer> tree = TreeUtil.buildSingle(list, 0);
        log.warn("{}", FastjsonUtil.toPrettyStr(tree));
        List<Tree<Integer>> treeList = TreeUtil.build(list, 0);
        log.warn("{}", FastjsonUtil.toPrettyStr(treeList));

    }
}
